define('common:widget/ui/ai/textArea/textArea', function(require, exports, module) {

  /**
   * @file 操作区prompt编辑
   * @author yuanmin
   */
  
  var san = require('common:widget/ui/ai/san');
  
  return san.defineComponent({
      template: ''
          + '<div class="textarea-wrapper">'
          + '    <div class="ai-tool-title {{isAiTip ? \'ai-tip-text\' : \'\'}}">{{title}}</div>'
          + '    <div class="input-area {{disabled && \'input-area-disable\'}}">'
          + '        <textarea'
          + '            type="input"'
          + '            value="{= content =}"'
          + '            disabled="{{disabled}}"'
          + '            placeholder="{{placeholder}}"'
          + '            on-focus="handlePromptFocus"'
          + '            on-input="handlePrompInput"'
          + '        ></textarea>'
          + '        <div class="foot">'
          + '            <div class="foot-inner">'
          + '                <div class="{{descLength === 0 && \'disbaled\'}}">{{ descLength }}</div>'
          + '                <div class="number">/{{ maxLength }}</div>'
          + '                <div'
          + '                    class="{{(descLength === 0 || disabled) && \'disbaled\'}} clear-btn"'
          + '                    on-click="handlePrompClear"'
          + '                >清空</div>'
          + '            </div>'
          + '        </div>'
          + '    </div>'
          + '    <div class="tips">'
          + '        <div'
          + '            s-for="item, index in list"'
          + '            class="tip-item {{disabled && \'tip-item-disabled\'}}"'
          + '            on-click="handleTipItemClick(index)"'
          + '        >'
          + '            {{item}}'
          + '        </div>'
          + '    </div>'
          + '</div>',
      initData: function () {
          return {
              content: '',
              descLength: 0,
              placeholder: '输入你的灵感…',
              maxLength: 200, // 文本框可输入字数的最大长度
              list: [],
              disabled: false, // 禁用态（生成时需要禁用全部的操作）
              title: '',
              isAiTip: false
          };
      },
      attached: function () {
          this.data.set('descLength', this.data.get('content').length);
          this.watch('content', function (value) {
              this.data.set('descLength', value.length);
              this.fire('input', value);
          });
  
      },
  
      handlePromptFocus: function () {
          this.fire('focus');
      },
      handlePrompInput: function () {
          var content = this.data.get('content');
          var maxLength = this.data.get('maxLength');
          // 截断处理
          this.data.set('content', content.slice(0, maxLength));
      },
      handlePrompClear: function () {
          if (this.data.get('disabled') || this.data.get('descLength') === 0) {
              return;
          }
          this.data.set('content', '');
          this.fire('clear');
      },
      handleTipItemClick: function (index) {
          if (this.data.get('disabled')) {
              return;
          }
  
          this.data.set('content', this.data.get('list')[index]);
  
          this.fire('select', {
              index,
              item: this.data.get('list')[index]
          });
      }
  });
  

});
